home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group02b.txt
/
000160_icon-group-sender_Tue Dec 10 07:57:42 2002.msg
< prev
next >
Wrap
Internet Message Format
|
2003-01-02
|
3KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id gBAEvWY04347
for icon-group-addresses; Tue, 10 Dec 2002 07:57:32 -0700 (MST)
Message-Id: <200212101457.gBAEvWY04347@baskerville.CS.Arizona.EDU>
X-Sender: whm@mail.mse.com
Date: Mon, 09 Dec 2002 20:35:48 -0700
To: icon-group@cs.arizona.edu
From: "William H. Mitchell" <whm@mse.com>
Subject: Hack for partial evaluation in Icon
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
James' mention of ML got me thinking about an ML feature I'd really like to
see in Icon: partial evaluation -- the ability to supply some parameters
for a function now and some later, with the function call taking place when
all parameters have been supplied.
It's a hack but here's a way to get that effect in Icon, albeit with an
unfortunate finiteness...
Here's a main program:
invocable all
link image
procedure main()
lftx := partial(left, "x")
every write(lftx(1 to 5, "."))
f := partial(left, "y", 5)
every write(f(!"abcd"))
every w := partial(write, "testing..." | "MORE testing...") do
every w(1 to 5)
s := set()
p := partial(insert,s)
p(1)
p(2)
p(s)
write(Image(s))
end
Here's the output:
x
x.
x..
x...
x....
yaaaa
ybbbb
ycccc
ydddd
testing...1
testing...2
testing...3
testing...4
testing...5
MORE testing...1
MORE testing...2
MORE testing...3
MORE testing...4
MORE testing...5
S1:[
2,
1,
S1]
Here's the hack...
record partial_record(proc, args)
global partials
procedure partial(args[])
static partial_num
initial {
partials := table()
partial_num := 0
}
partial_num +:= 1
partials[partial_num] := partial_record(args[1], args[2:0])
return "do_partial_" || partial_num
end
#
# I need a way to make these on the fly! Until then...
#
procedure do_partial_1(args[])
r := partials[1]
suspend r.proc!(r.args|||args)
end
procedure do_partial_2(args[])
r:= partials[2]
suspend r.proc!(r.args|||args)
end
procedure do_partial_3(args[])
r:= partials[3]
suspend r.proc!(r.args|||args)
end
procedure do_partial_4(args[])
r:= partials[4]
suspend r.proc!(r.args|||args)
end
procedure do_partial_5(args[])
r:= partials[5]
suspend r.proc!(r.args|||args)
end
Pop quiz for comparative languages students: The above implementation
relies on a procedure named "partial" to indicate that partial evaluation
should be done. In ML such a cue is not necessary. Can partial evaluation
be added to Icon without requiring a cue of some sort?